#include "vent.h"
#include <cstdlib>
#include <iostream>
using namespace std;

float Vent::offset = 0.0;


/******************************/
/* Constructeur / Destructeur */
/******************************/

Vent::Vent()
{
_nbPas=0;
_force=0;
}

Vent::~Vent()
{
}


/*************************/
/*** Getters / Setters ***/
/*************************/

float Vent::getForce()
{
  //offset correspond a l'intervention de l'utilisateur pour l'augmentation
  //ou la diminution de la force du vent vi a un p'tit clic droit
  
  if(_force > 0) _force += offset;
  else _force -= offset;

  if(_force>5.0) _force = 5.0;
  else if(_force < -5.0) _force = -5.0;

  offset=0.0;
  return _force;
}

int Vent::getDirection()
{
  return _direction;
}


/****************************/
/********* Callbacks ********/
/****************************/

void Vent::onTimerEvent(int )
{

  if(_nbPas%75 ==0)
  {
    srand(_nbPas+1);
    float delta = ( ((float)(rand())) - RAND_MAX/2.0 )/RAND_MAX;
    _force += delta*0.5;
    if(_force >5.0) _force =5.0;
    else if(_force < -5.0) _force=-5.0;
    
    if(_force < 0.0) _direction=-1;
    else _direction = 1;
 /*  cout << "direction : " << _direction << endl;
   cout << "force : " << _force << endl;*/
 }
  _nbPas++;
}
